<?
	include("../classes/clsDB.php");
	include("../classes/clsMail.php");
	$r=new ReturnRecord();
	
	date_default_timezone_set("Australia/Brisbane");
	$CurDay=date("w");
	$Interval=4-(1*$CurDay); // 0=sunday so 4=thursday
	if($Interval<0){ // past thurday so time till next week
		$Interval=7+$Interval;
	}
	$TheToDate=date("Y-m-d h:i:s",mktime(12,0,0,date("m"),date("d")+$Interval+7,date("Y")));
	$TheFromDate=date("Y-m-d h:i:s",mktime(12,0,0,date("m"),date("d")+$Interval,date("Y")));
	
	print $TheFromDate." -> ".$TheToDate."<br>\n";
	
	$EmailBody="";  
	
	$rrslt=$r->RawQuery("SELECT DISTINCT property.id,property.propertyName,location,propertyDetails,imageMain FROM property,room,weeklysale WHERE property.id=room.propertyID AND room.id=weeklysale.roomID AND weeklysale.saledate<'$TheToDate' AND weeklysale.saledate>='$TheFromDate'");
	if($rrslt){
		while($rmyrow=mysql_fetch_row($rrslt)){
			$EmailBody.='<table width="90%" border="0" cellpadding="4" cellspacing="0" align="center" id="saleAvailable"><tr><td align="left">';
			if($rmyrow[4]!=""){
				$EmailBody.='<img src="http://'.$_SERVER['HTTP_HOST'].'/images/uploads/'.$rmyrow[4].'"  align="left">';
			};
			$EmailBody.='<strong>'.$rmyrow[1].'</strong><br>'.$rmyrow[2].'<br>'.$rmyrow[3].'</td></tr> </table><br><br>';
		};
	};
  
	
	//print $EmailBody;
	
	$SQL2="SELECT id,firstName,lastName,email FROM members WHERE emailSubscribe='1'";
	$rslt=$r->rawQuery($SQL2);
	while($myrow=mysql_fetch_assoc($rslt)){
		
			$m=new SendMail();
			$m->Template("email_template.htm");
			$m->To(array($myrow['firstName']=>$myrow['email'],"Click2go Admin"=>"info@".eregi_replace("www\.","",$_SERVER['HTTP_HOST'])));
			$m->From("Click2go","info@".eregi_replace("www\.","",$_SERVER['HTTP_HOST']));
			$m->Subject("The Juice Newsletter");
			$m->Merge(array("ServerUrl"=>"http://".$_SERVER['HTTP_HOST'],"Body"=>$EmailBody,"ServerEmail"=>"info@".eregi_replace("www\.","",$_SERVER['HTTP_HOST'])));
			$m->Send();
			
			echo"Email Sent To ->$myrow[email] <br>\n";
	}

?>